package com.informatica.test.gwt.server;

import java.io.InputStream;
import java.util.Properties;

import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.node.ObjectNode;

import com.informatica.test.gwt.client.BetService;
import com.informatica.test.gwt.shared.FieldVerifier;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class BetServiceImpl extends RemoteServiceServlet implements
    BetService {

  public String greetServer(String input) throws IllegalArgumentException {
    // Verify that the input is valid. 
    if (!FieldVerifier.isValidName(input)) {
      // If the input is not valid, throw an IllegalArgumentException back to
      // the client.
      throw new IllegalArgumentException(
          "The specified value is incorrect");
      
    }
    
    	Properties confProps = new Properties();
    	confProps.setProperty("baseUrl","http://93.153.167.139:16006/saas");
    	confProps.setProperty("userName", "yurova92@gmail.com");
    	confProps.setProperty("password", "ghbdtnbr");
    	
    	Configuration configuration = new Configuration(confProps);
    	BaseDelegate BD=new BaseDelegate(configuration,new ObjectMapper(),new UserContext());

    	JsonNode PostLogin=BD.post("/v2/user/login?login={0}&password={1}", "yurova92@gmail.com", "ghbdtnbr");
    	        	//JsonNode myTask=BD.post("v2/job?taskId={0}&taskType={1}", 15, "MTT");
    	JsonNode task1 = BD.get("v2/mttask/{0}",17);
    	JsonNode parameters = task1.get("parameters");
    	ObjectNode myparameter = (ObjectNode) parameters.get(3);
    	myparameter.put("text", input);
    	BD.post("v2/mttask/{0}", task1, 17);
    	BD.post("v2/job?taskId={0}&taskType={1}", 17, "MTT");
    	

   return myparameter.toString();
 }
}